﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Ping
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Runtime.CompilerServices;
using UnityEngine.Bindings;

#nullable disable
namespace UnityEngine
{
  /// <summary>
  ///   <para>Ping any given IP address (given in dot notation).</para>
  /// </summary>
  [NativeHeader("Runtime/Export/Networking/Ping.bindings.h")]
  public sealed class Ping
  {
    internal IntPtr m_Ptr;

    /// <summary>
    ///   <para>Perform a ping to the supplied target IP address.</para>
    /// </summary>
    /// <param name="address"></param>
    public Ping(string address) => this.m_Ptr = Ping.Internal_Create(address);

    ~Ping() => this.DestroyPing();

    [ThreadAndSerializationSafe]
    public void DestroyPing()
    {
      if (this.m_Ptr == IntPtr.Zero)
        return;
      Ping.Internal_Destroy(this.m_Ptr);
      this.m_Ptr = IntPtr.Zero;
    }

    [FreeFunction("DestroyPing", IsThreadSafe = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void Internal_Destroy(IntPtr ptr);

    [FreeFunction("CreatePing")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern IntPtr Internal_Create(string address);

    /// <summary>
    ///   <para>Has the ping function completed?</para>
    /// </summary>
    public bool isDone => !(this.m_Ptr == IntPtr.Zero) && this.Internal_IsDone();

    [NativeName("GetIsDone")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern bool Internal_IsDone();

    /// <summary>
    ///   <para>This property contains the ping time result after isDone returns true.</para>
    /// </summary>
    public extern int time { [MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>The IP target of the ping.</para>
    /// </summary>
    public extern string ip { [NativeName("GetIP"), MethodImpl(MethodImplOptions.InternalCall)] get; }
  }
}
